package cn.xuchunh.sword;

/**
 * Created by XuChunH on 2016/9/18.
 */
public class ReverseSentence {

    public String solution(String str) {
        if(str == null){
            return null;
        }
        if(str.isEmpty()) {
            return "";
        }
        String[] array = str.split(" ");
        if (array.length == 0){
            return str;
        }
        int mid = (array.length - 1) / 2;
        for (int i = 0; i <= mid; i++) {
            String temp = array[i];
            array[i] = array[array.length - 1 -i];
            array[array.length - 1 - i] = temp;
        }
        String result = "";
        for (String s : array) {
            result += s + " ";
        }
        return result.trim();
    }

    public static void main(String[] args) {
        System.out.println(new ReverseSentence().solution(" "));
    }

}
